<?php
namespace app\common\model;

use think\Model;

class Company extends Model
{
    //单位
    public function company($page,$limit){
        $list = db('company')
            ->where('company_status',"<>","3")
            ->where('pid',0)
            ->page($page,$limit)
            ->select();
        $count = db('company')
            ->where('company_status',"<>","3")
            ->where('pid',0)
            ->count();
        foreach ($list as $k=>$v){
            //下属部门数量
            $list[$k]['downnum'] = db('department')->where('company_id',$list[$k]['company_id'])->count();
        }
        return ['count' => $count,'data' => $list];
    }
    //部门
    public function department($page,$limit){
        $list = db('department')
            ->alias('d')
            ->join('company c',"d.company_id = c.company_id")
            ->where('d.department_status',"<>","3")
            ->page($page,$limit)
            ->select();
        $count = db('department')
            ->alias('d')
            ->join('company c',"d.company_id = c.company_id")
            ->where('d.department_status',"<>","3")
            ->count();
        return ['count' => $count,'data' => $list];
    }
    public function getwherelist($where){
        $list = db('company')
            ->where($where)
            ->where('company_status',1)
            ->select();
        return $list;
    }

}